// pages/mine/mine.js
const app = require('../../utils/ajax.js');
const {
  weixin
} = require('../../utils/value.js');
const config = require('../../utils/config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isHideDepartment: true,
    employee_name: '',
    employee_head_portrait: '../image/bb.jpg',
    work_unit_id: '',
    department_id: '',
    position_id: '',
    position_is_evaluate: '',
    employee_status: '',
    valiate_status: '',
    money1: 200.00,
    money2: 600.00,
    userInfo:{
      name:'---',
      telephone:'-----',
      accompany_money:'0.00',
      bed_money:'0.00'
    }
  },

  //跳转部门
  toDepartment() {
    const {
      valiate_status,
      work_unit_id,
      department_id
    } = this.data;
    if (valiate_status == 2) {
      wx.showToast({
        title: '待审核中',
      });
      return;
    }
    wx.navigateTo({
      url: '../department/department?work_unit_id=' + work_unit_id + '&department_id=' + department_id,
    })
  },

  //跳转项目
  toTest() {

  },

  //跳转修改密码
  toForget() {
    wx.navigateTo({
      url: '../login/forget',
    })
  },

  //判断经理或员工
  showLine(a) {
    let four = this.data.four;
    //员工登陆时
    if (a) {
      four = four.slice(1);
    }
    this.setData({
      four
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //this.handleGetEmployeeInfo();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    //this.handleGetEmployeeInfo();
    this.handleGetUserInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    //解决下拉不回弹
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  /**
   * 跳转到用户信息页
   */
  handleRedirectToUserInfo: function() {
    wx.navigateTo({
      url: './userInfo',
    })
  },

  /**
   * 跳转到充值页面
   */
  handleRedirectToRecharge: function(e) {
    const type1 = e.currentTarget.dataset.type;
    if(type1==='2'){
      wx.showToast({
        title: '该功能尚未开放',
        icon:'none',
        duration:1000
      })
      return;
    }
    wx.navigateTo({
      url: './recharge?type=' + type1,
    })
  },

  /**
   * 跳转到扣费记录页
   */
  handleRedirectToRecord: function() {
    wx.navigateTo({
      url: './deductionRecord',
    })
  },

  /**
   * 获取用户信息
   */
  handleGetUserInfo: function() {
    const url = config.ServerUrl + weixin.USER_MSG;
    const param={weixin_id:app.getData('open_id')};
    wx.showLoading({
      title: '',
    });
    const _this=this;
    app.doGet(url,param,function(res){
      if(res.state===1){
        let {accompany_money,bed_money}=res.data;
        accompany_money = Number(accompany_money);
        bed_money=Number(bed_money);
        if(bed_money<=0){
          wx.showToast({
            title: '账户余额不足，请及时充值',
            icon:'none',
            duration:2000
          })
        }else{
          wx.hideLoading();
        }
        _this.setData({userInfo:res.data});
        
      }else{
        wx.showToast({
          title: res.msg,
          icon:'none',
          duration:1000
        })
      }
    })
  }
})